import request from "@/utils/request";

const baseUri = "/mv1/api/product";

/**
 * 获取角色分页数据
 *
 * @param queryParams
 */
export function getProductList(queryParams?: ProductQuery) {
  return request({
    url: baseUri + "/",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取详情
 *
 * @param id
 */
export function getProductDetail(id: number) {
  return request({
    url: baseUri + "/detail/" + id,
    method: "get",
  });
}

/**
 * 初始化编辑数据
 */
export function getProductOptions() {
  return request({
    url: baseUri + "/options",
    method: "get",
  });
}

/**
 * 初始化编辑数据
 */
export function getSearchProducts(data: any) {
  return request({
    url: baseUri + "/search_options",
    method: "get",
    params: data,
  });
}

export function copyProduct(id: number) {
  return request({
    url: baseUri + "/copy/" + id,
    method: "post",
    data: {},
  });
}

export function createProduct(data: ProductForm) {
  return request({
    url: baseUri + "/add",
    method: "post",
    data: data,
  });
}

export function updateProduct(id: number, data: ProductForm) {
  return request({
    url: baseUri + "/edit/" + id,
    method: "put",
    data: data,
  });
}


/**
 * 批量删除，多个以英文逗号(,)分割
 *
 * @param ids
 */
export function deleteProduct(ids: string) {
  return request({
    url: baseUri + "/" + ids,
    method: "delete",
  });
}

/**
 * 角色查询参数
 */
export interface ProductQuery extends PageQuery {
  page?: number;
  limit?: number;
  product_type?: number;
  shop_id?: number;
  category_id?: number;
  keywords?: string;
}

/**
 * 分页对象
 */
export interface ProductPageVO {
  id?: number;
  sn?: string;
  title?: number;
  thumb?: string;
  category_title?: string;
  shop_title?: string;
  status?: number;
  bag_price?: number;
  price?: number;
  update_time?: Date;
}

export interface ProductForm {
  id?: number;
  title?: string;
  thumb?: string;
  category_id?: string;
  shop_id?: string;
  stall_id?: string;
  bag_price?: number;
  cost_price?: number;
  price?: number;
  sort?: number;
  skus?: any;
  // sn?: any;
  status?: number;
  step?: number;
  spec_type?: number;
  stock?: number;
  weight?: number;
  stock_cal_type?: number;
  select_amount?: number;
  product_type?: number;
  content?: string;
  product_feed?: string;
  product_taste?: string;
  min_buy?: number;
  is_single_seller?: number;
  limit_num?: number;
}

export interface SpecForm {
  title?: string;
  id?: number;
  tagTitle?: string;
  tagPrice?: number;
  spec_items?: any;
}

export interface ComboForm {
  title?: string;
  id?: number;
  amount?: number;
  is_multi?: number;
  spec_items?: any;
}
